Repository navigation
Conversation
…s in to_pandas An index level whose pandas metadata says string but whose Arrow type was changed afterwards (for example with Table.set_column) was converted to strings by the restored extension dtype. Only restore the string dtype when the Arrow column is a string or binary type or null.
Author
|
I pushed one more commit. Restoring the extension dtype from the metadata could also turn an index level that was replaced after |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Table.from_pandasstores the extension dtype of each index level in the pandas metadata (for examplenumpy_type: "Int64"), butto_pandasonly applies it to data columns. Index levels come back with the default dtype for the Arrow type, and a nullable integer index with missing values becomes afloat64index:What changes are included in this PR?
_extract_index_levelinpandas_compat.pynow converts an index level with the extension dtype recorded in the metadata when that dtype implements__from_arrow__, through the dtype's__from_arrow__, so the level is converted once. A user-suppliedtypes_mapperstill takes precedence, as it does for data columns, and dictionary (categorical) levels are left to the existing path.Are these changes tested?
Yes.
test_roundtrip_index_with_extension_dtype(single index and as a MultiIndex level) coversInt64,Float32,boolean,string,UInt8andint64[pyarrow]; it fails on main for all six and passes with the change.test_pandas.py,parquet/,interchange/andtest_feather.pyotherwise give identical results with and without the change, on pandas 3.1.1 and 2.3.3.Are there any user-facing changes?
Yes:
to_pandas()(andpd.read_parquet) returns an index with the original nullable or Arrow-backed dtype instead of the default dtype for the Arrow type.This PR contains a "Critical Fix". A nullable integer index with missing values was converted to a float index, and integers above 2**53 lose precision in that conversion (
2**53 + 1comes back as2**53).Was AI used for this PR?
The implementation and tests were written with AI assistance.
PR code and description written by:
Reviewed before submission by: